package lib.bone.audit.workload.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

/**
 * 工作量使用记录
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "workload_use_log")
@EntityListeners(AuditingEntityListener.class)
@ApiModel(value = "科研项目工作量抵扣记录")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class  WorkloadUseLog {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @ApiModelProperty(value = "科研项目工作量抵扣记录",name = "id")
    String id;

    /**
     * 周期ID
     */
    @ApiModelProperty("周期ID")
    @Column(name = "cycle_id")
    String cycleId;

    @ApiModelProperty(value = "用户ID",notes = "对应 system-user 表 ID")
    @Column(name = "user_id")
    Long userId;

    @ApiModelProperty(value = "使用的工作量")
    @Column(name = "workload",scale = 2)
    Double workload;

    @Column(name = "workload_id")
    @ApiModelProperty(value = "工作量记录ID",name = "id")
    String workloadId;

    @ApiModelProperty(value = "工作量类型",notes = "科研工作量，教学工作量，管理工作量，兼职工作量")
    @Column(name = "workload_type")
    String workloadType;

    @ApiModelProperty(value = "用途",notes = "抵扣")
    @Column(name = "use_method")
    String useMethod;

    /**
     * 关联科研项目ID
     */
    @ApiModelProperty(value = "关联ID",notes = "根据科研项目类型不同，对应不同的表")
    @Column(name = "link_id")
    String linkId;

    @ApiModelProperty(value = "管理名称",notes = "论文为标题等")
    @Column(name = "link_name")
    String linkName;



    @ApiModelProperty(value = "工作量获取日期",notes = "workload 表中 createdTime")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @Column(name = "workload_date")
    Date workloadDate;



    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;
    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        WorkloadUseLog useLog = (WorkloadUseLog) o;
        return id != null && Objects.equals(id, useLog.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
